﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CommonLib {
    public class Scene {
        private Primitive[] primitive;
        private Primitive[] lights;
        public Scene()
        {
            initialize();
        }

        private void initialize() {
            List<Primitive> prims = new List<Primitive>();
            List<Primitive> lis = new List<Primitive>();

            // ground plane
            Primitive plane01 = new Plane(new Vector3c(0, -4.4, 0), new Vector3c(0, 1, 0), false);
            plane01.Material = new Material(new Vector3c(0.4, 0.3, 0.3), 1.0, 0.0, 0.0, 1.0);
            prims.Add(plane01);

            // big sphere
            Primitive sphere01 = new Sphere(new Vector3c(2, 0.8, 3), 2.5, false);
            sphere01.Material = new Material(new Vector3c(0.7, 0.7, 1.0), 0.0, 0.2, 0.8, 1.3);
            prims.Add(sphere01);

            // small sphere
            Primitive sphere02 = new Sphere(new Vector3c(-5.5, -0.5, 7), 2, false);
            sphere02.Material = new Material(new Vector3c(0.7, 0.7, 1.0), 0.1, 0.5, 0.0, 1.3);
            prims.Add(sphere02);

            // light source 1
            Primitive light01 = new Sphere(new Vector3c(0, 5, 5), 0.1, true);
            light01.Material = new Material(new Vector3c(0.4, 0.4, 0.4), 0.0, 0.0, 0.0, 1.0);
            prims.Add(light01);
            lis.Add(light01);

            // light source 2
            Primitive light02 = new Sphere(new Vector3c(-3, 5, 1), 0.1, true);
            light02.Material = new Material(new Vector3c(0.6, 0.6, 0.8), 0.0, 0.0, 0.0, 1.0);
            prims.Add(light02);
            lis.Add(light02);

            // extra sphere
            Primitive sphere03 = new Sphere(new Vector3c(-1.5, -3.8, 1), 1.5, false);
            sphere03.Material = new Material(new Vector3c(1.0, 0.4, 0.4), 0.0, 0.0, 0.8, 1.0);
            prims.Add(sphere03);

            // back plane
            Primitive plane02 = new Plane(new Vector3c(-4.457, 0, 11.142), new Vector3c(0.4, 0, -1), false);
            plane02.Material = new Material(new Vector3c(0.5, 0.3, 0.5), 0.6, 0.0, 0.0, 1.0);
            prims.Add(plane02);

            // ceiling plane
            Primitive plane03 = new Plane(new Vector3c(0, 7.4, 0), new Vector3c(0, -1, 0), false);
            plane03.Material = new Material(new Vector3c(0.4, 0.7, 0.7), 0.5, 0.0, 0.0, 1.0);
            prims.Add(plane03);

            // grid
            for (int x = 0; x < 8; x++) for (int y = 0; y < 7; y++) {
                Primitive prim = new Sphere(new Vector3c(-4.5f + x * 1.5f, -4.3f + y * 1.5f, 10), 0.3, false);
                prim.Material = new Material(new Vector3c(0.3, 1.0, 0.4), 0.6, 0, 0, 1.0);
                prims.Add(prim);
            }

            this.primitive = prims.ToArray();
            this.lights = lis.ToArray();
        }
        public int CountPrimitive() {
            return primitive.Length;
        }
        public Primitive GetPrimitive(int index) {
            return primitive[index];
        }
        public int CountLight() {
            return lights.Length;
        }
        public Primitive GetLight(int index) {
            return lights[index];
        }
    }
}
